import axios from '~/axios'
import { joinPramas } from './manager'

//产品档案新--------------------------
/**
 * 添加产品类型
 * @param {*} paramIo 
 */
export function addProductType(paramIo) {
  return axios({
    url: '/api/backend/product-types/add',
    method: 'post',
    data: paramIo
  })
}

/**
 * 删除产品类型
 * @param {*} paramIo 
 */
export function deleteProductType(productTypeId) {
  return axios({
    url: '/api/backend/product-types/delete/'+productTypeId,
    method: 'post'
  })
}

/**
 * 更新产品类型
 * @param {*} paramIo 
 */
export function updateProductType(productTypeId,paramIo) {
  paramIo.productTypeId = productTypeId
  return axios({
    url: '/api/backend/product-types/update',
    method: 'post',
    data: paramIo
  })
}

/**
 * 获取产品类型列表
 * @param {*} paramIo 
 */
export function getProductTypeList(paramIo) {
    return axios({
      url: '/api/backend/product-types/list',
      method: 'post',
      data: paramIo
    })
}

export function getProductTypeByType(factorType) {
      return axios({
        url: '/api/backend/product-types/get/'+factorType,
        method: 'post'
      })
}

/**
 * 添加产品
 * @param {*} paramIo 
 */
export function addProduct(paramIo) {
    return axios({
      url: '/api/backend/product/add',
      method: 'post',
      data: paramIo
    })
  }
  
  /**
   * 删除产品
   * @param {*} paramIo 
   */
  export function deleteProduct(productId) {
    return axios({
      url: '/api/backend/product/delete/'+productId,
      method: 'post'
    })
  }
  
  /**
   * 更新产品
   * @param {*} paramIo 
   */
  export function updateProduct(productId,paramIo) {
    paramIo.productId = productId
    return axios({
      url: '/api/backend/product/update',
      method: 'post',
      data: paramIo
    })
  }

  export function updateShipId(paramIo) {
    let finalUrl = joinPramas("/api/backend/product/updateShipId", paramIo)
    return axios({
      url: finalUrl,
      method: 'get'
    })
  }
  
  /**
   * 获取产品
   * @param {*} paramIo 
   */
  export function getProductList(paramIo) {
      return axios({
        url: '/api/backend/product/list',
        method: 'post',
        data: paramIo
      })
  }

  /**
 * 添加产品和产品大类
 * @param {*} paramIo 
 */
export function addProductAndType(paramIo) {
  return axios({
    url: '/api/backend/product/addProductAndType',
    method: 'post',
    data: paramIo
  })
}


  /**
 * 添加备件
 * @param {*} paramIo 
 */
export function addProductPart(paramIo) {
    return axios({
      url: '/api/backend/product-parts/add',
      method: 'post',
      data: paramIo
    })
  }
  
  /**
   * 删除备件
   * @param {*} paramIo 
   */
  export function deleteProductPart(productPartId) {
    return axios({
      url: '/api/backend/product-parts/delete/'+productPartId,
      method: 'post'
    })
  }
  
  /**
   * 更新备件
   * @param {*} paramIo 
   */
  export function updateProductPart(partId,paramIo) {
    paramIo.partId = partId
    return axios({
      url: '/api/backend/product-parts/update',
      method: 'post',
      data: paramIo
    })
  }
  
  /**
   * 获取备件
   * @param {*} paramIo 
   */
  export function getProductPartList(paramIo) {
      return axios({
        url: '/api/backend/product-parts/list',
        method: 'post',
        data: paramIo
      })
  }

  /**
   * 上传批量产品文件
   * @param {*} paramIo 
   */
  export function uploadFile(paramIo) {
    return axios({
      url: '/api/backend/product/upload',
      method: 'post',
      data: paramIo,
      headers: {
        'Content-Type':'multipart/form-data'
      },
      timeout: 3000000
    })
  }

  /**
   * 解析批量产品文件
   * @param {*} paramIo 
   */
  export function batchCreateProduct(paramIo,shipId) {
    let urlStr = '/api/backend/product/batch';
    if (shipId !== null && shipId !== undefined) {
      urlStr += `?shipId=${shipId}`;
    }
    return axios({
      url: urlStr,
      method: 'post',
      data: paramIo,
      headers: {
        'Content-Type':'application/json'
      },
    })
  }

    /**
   * 获取未绑定船舶的产品列表
   * @param {*} paramIo 
   */
  export function listNoRelatedProduct(paramIo) {
      return axios({
        url: '/api/backend/product/listNoRelated',
        method: 'post',
        data: paramIo
      })
  }


//产品档案新--------------------------

//统计--------------------------
/**
 * 产品发货统计
 * @param {*} paramIo 
 */
export function deliverStatistic() {
  return axios({
    url: '/api/backend/product/deliverStatistic',
    method: 'post'
  })
}


/**
 * 产品维修统计
 * @param {*} paramIo 
 */
export function repairResultInfo() {
  return axios({
    url: '/api/backend/productRepairs/statisticForMonth',
    method: 'post'
  })
}
//统计--------------------------


//产品及备件配置信息--------------------------
    /**
   * 获取备件列表
   * @param {*} paramIo 
   */
  export function listRel(paramIo) {
      return axios({
        url: '/api/backend/product-rel/getRelList',
        method: 'post',
        data: paramIo
      })
  }
//产品及备件配置信息--------------------------
